
public class Test {
    static class WaitTask implements Runnable{
        private Object locker;

        public WaitTask(Object locker) {
            this.locker = locker;
        }

        @Override
        public void run() {
            synchronized (locker){
                try {
                    System.out.println("wait开始");
                    locker.wait();
                    System.out.println("wait结束");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }
    static class notifyTask implements Runnable{
        private Object locker;
        public notifyTask(Object locker) {
            this.locker = locker;
        }

        @Override
        public void run() {
            synchronized (locker){
                System.out.println("notify开始");
                locker.notify();
                System.out.println("notify结束");
            }
        }
    }

    public static void main(String[] args) {
        Object locker = new Object();
        WaitTask waitTask = new WaitTask(locker);
        notifyTask notifyTask = new notifyTask(locker);
        Thread thread = new Thread(waitTask);
        Thread thread1 = new Thread(notifyTask);
        thread.start();
        thread1.start();
    }
}
